using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace mailer
{
    public partial class MailForm : Form
    {
        private string mail_content;
        private string mail_title;
        private bool mail_ishtml;

        public bool Mail_ishtml
        {
            get { return mail_ishtml; }
            set { mail_ishtml = value; }
        }
        
        public string Mail_Content
        {
            set { mail_content = value; }
            get { return mail_content; }
        }

        public string Mail_Title
        {
            set { mail_title = value; }
            get { return mail_title; }
        }
        

        public MailForm()
        {
            InitializeComponent();
        }

        public void Initial()
        {
            this.Title_TextBox.Text = mail_title;
            this.webBrowser1.DocumentText = this.mail_content;
            this.webBrowser1.Document.Encoding = this.webBrowser1.Document.DefaultEncoding;
            this.Refresh();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sb = new StringBuilder();

            if(this.openFileDialog1.ShowDialog()!=DialogResult.OK)
            {
                return;
            }
            else
            {
                string strLine;
                FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                StreamReader m_streamReader = new StreamReader(fs);
                m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                sb.AppendLine((strLine = m_streamReader.ReadLine()));
                while (strLine != null)
                {
                    sb.AppendLine((strLine = m_streamReader.ReadLine()));
                }
                m_streamReader.Close();    
            }

            this.mail_content = sb.ToString();
            
            
            this.webBrowser1.DocumentText = this.mail_content;
            this.webBrowser1.Document.Encoding = this.webBrowser1.Document.DefaultEncoding;
                 
            this.Refresh();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.mail_title = this.Title_TextBox.Text;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(webBrowser1.DocumentText);
            this.Refresh();
        }
    }
}